﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>测试</title>
    <script src="js/vue.js"></script>
    <script src="js/jquery-3.2.1.min.js"></script>
    <script src="js/common.js"></script>
    <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">
</head>
<body>
    <div id="app">
        {{navigator1}}
        <div>
            {{huanjing}}
        </div>
        <input type="button" v-on:click="login" value="跳转至页面" />
        <input type="button" v-on:click="pay" value="支付" />
        <input type="button" v-on:click="share" value="分享" />
        <input type="button" v-on:click="getToken" value="获取token" />
        <input type="button" v-on:click="getLocation" value="获取地理位置">
        <input type="button" v-on:click="getUserInfo" value="获取用户信息(代理测试)">
    </div>
</body>
</html>
<script>
    pushdata = function (data) {
        $.ajax({
            url: "/Api/test/pushData",
            data: data,
            type: "POST",
            success: function (data) {
                alert("回调已发送到服务器");
            },
            error: function (data) {
                alert("发送失败");
            }
        })
    }
    var page=new Vue({
        el: '#app',
        data: {
            navigator1: navigator.userAgent,
            huanjing:isWeiXin()?"微信":isFeiyu()?"飞羽客户端":"其他浏览器"
        },
        methods: {
            login: function () {
                if (isWeiXin()) {
                    alert("微信登录");
                } else if (isFeiyu()) {
                    //跳转地址,是否可以返回
                    //com.app.feiyu.activity.RegisterActivity
                    feiyu.toPage("com.app.feiyu.activity.LoginActivity",false);
                } else {
                    alert("h5一般登录");
                }
            },
            pay: function () {
                if (isWeiXin()) {
                    alert("微信支付");
                } else if (isFeiyu()) {
                    //单号、订单类型、支付成功回调、支付失败回调
                    var data = feiyu.pay("123456789", 0);
                    data.nethod = "pay";
                    pushdata(data);
                } else {
                    alert("请下载客户端完成支付");
                }
            }, share: function () {
                if (isWeiXin()) {
                    alert("微信分享");
                } else if (isFeiyu()) {
                    //标题、简述、跳转地址、图片地址、支付成功回调、支付失败回调
                    var data = feiyu.share("飞羽体育", "飞羽体育是一款关于订场app，主要目标人群是运动爱好者。功能包括GPS精准定位附近运动休闲娱乐场馆，为您提供方便、快捷的运动方式及参考，让你感受运动的快乐。", location.href, thisUrl + '/Wap/images/vult17.png')
                    data.nethod = "share";
                    pushdata(data);
                } else {
                    alert("在微信或app中打开才能分享");
                }
            },
            getToken: function () {
                if (isFeiyu()) {
                    //成功回调、失败回调
                    var data = feiyu.getToken();
                    data.method = "gettoken";
                    pushdata(data);
                } else {
                    alert("不在app中拿不到");
                }
            },
            getLocation: function () {
                if (isFeiyu()) {
                    //成功回调、失败回调
                    var data = feiyu.getLocation();
                    data.method = "getLocation";
                    pushdata(data);
                } else {
                    alert("不在app中拿不到");
                }
            },
            getUserInfo: function () {
                var that = this;
                $.ajax({
                    url: "http://changguan.localhost.egaopa.com" + '/Api/Mine/GetMyInfo',
                    type: "POST",
                    data: { name: "张三", age: 10 },
                    dataType: "json",
                    success: function (data) {
                        if (data.errcode == 0) {
                            alert("请求成功");
                        } else if (data.errcode == -1) {
                            alert(data.errmsg);
                        } else if (data.errcode == -2) {
                            alert("未登录");
                            that.login();
                        }
                    },
                    error: function (data) {
                        alert("请求响应失败");
                    }
                })
            }
        }
    })
</script>